function each(data) {
    let iterator = data[Symbol.iterator]();
    let item = {
        done: false
    };
    while (!item.done) {
        item = iterator.next();
        if (!item.done) {
            console.log(item.value)
        }
    }
}

let arr = [1, 2, 3];
let nodeList = document.getElementsByTagName('p');

each(arr);
each(nodeList);